# 1、栈(Stack) -- 后进先出(LIFO)
# 手写实现
class Stack:

    def __init__(self):
        self.items = []

    def push(self, item):
        """入栈"""
        self.items.append(item)

    def pop(self):
        """出栈"""
        if not self.is_empty():
            return self.items.pop()

    def peek(self):
        """查看栈顶元素"""
        return self.items[-1] if not self.is_empty() else None

    def is_empty(self):
        return len(self.items) == 0

    def size(self):
        return len(self.items)


# 测试
stack = Stack()
stack.push(1)
stack.push(2)
print(stack)
print(stack.pop())  # 输出 2